
<!DOCTYPE html>
<html>
	<head>		
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title></title>
		<script type="text/javascript" src="./rtmp_player/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="rtmp_player/swfplay.js"></script>
        
        <script type="text/javascript">
		jQuery.support.cors = true;
		
		var jsessionID="";
		var jtermsn="";
		var serverip="";
		var talkId="";//  记录talkId   关闭对讲时需要用到这个参数
		
		//登录
		function login() {
			serverip=$("#serverip").val();			
			var account= $("#account").val();
			var password=$("#password").val();	
			
			var param='{'+'"account":"'+account+'","pwd":"'+password+'"'+'}';			
			
			$.ajax({
            type: 'POST',
			url: 'http://'+serverip+':52467/openApi/login.dcw',
			data: param,
			cache:false,			
			contentType:'application/json',
			dataType: 'json',
            success: function(result){
                 if(result.code == 200){
					 jsessionID=result.data.jssesionId;
					 $("#jssesionId").attr("value", jsessionID);
					 // alert('登录成功，会话ID:'+jsessionID);
					 //loadInfo();
				   } else {
					  alert(result.msg);
				   }
			 },            
		   });
		   
		}
	
	
	//获取设备id
	function getTermSn(){
		var jssesionId=$("#jssesionId").val();			
		var vin= $("#devicename").val();
		
		var param='{'+'"vin":"'+vin+'"'+'}';		
		
		$.ajax({
            type: 'POST',
			url: 'http://'+serverip+':52467/openApi/deviceInfoByVin.dcw',
			data:param,
			cache:false,			
			contentType:'application/json',
			headers: {
                'jssesionId': jssesionId  //jssesionId要放在header中
            },
			dataType: 'json',
            success: function(result){
                 if(result.code == 200){
					 $("#termsn").attr("value", result.data.termSn);
				   } else {
					  alert(result.msg);
				   }
			 },            
		   });
		
		}		
		
		
		//获取设备在线状态		
		function getOnlineStatus(){
			var jssesionId=$("#jssesionId").val();			
			var nmsName=$("#devicename").val();
			var param='{'+'"nmsName":"'+nmsName+'"'+'}';
			
			$.ajax({
            type: 'POST',
			url: 'http://'+serverip+':52467/openApi/deviceInfoByTermSn.dcw',
			data:param,
			cache:false,			
			contentType:'application/json',
			headers: {
                'jssesionId': jssesionId  //jssesionId要放在header中
            },
			dataType: 'json',
            success: function(result){
                 if(result.code == 200){
					 if(result.data.online==1){
						     $("#onlineStatus").attr("value", "在线");
					   }else{
						     $("#onlineStatus").attr("value", "不在线");
					   }
				   } else {
					  alert(result.msg);
				   }
			 },            
		   });
		
		}
		
		
		//获取gps定位状态
		function getLocStatus(){
			var jssesionId=$("#jssesionId").val();			
			var nmsName=$("#devicename").val();
			var param='{'+'"nmsName":"'+nmsName+'"'+'}';

			//注意：获取到的gps坐标未 wgs84坐标系，如果需要在地图上显示，需要转换成对应地图的坐标系
			$.ajax({
            type: 'POST',
			url: 'http://'+serverip+':52467/openApi/getDeviceGPStatus.dcw',
			data:param,
			cache:false,			
			contentType:'application/json',
			headers: {
                'jssesionId': jssesionId  //jssesionId要放在header中
            },
			dataType: 'json',
            success: function(result){
                 if(result.code == 200){
					  if(result.data.status==1){					   
						   $("#gpsStatus").attr("value", "已定位");
						   $("#longitude").attr("value",  result.data.longitude);
						   $("#latitude").attr("value", result.data.latitude);
					   }else{
						   $("#gpsStatus").attr("value", "未定位");  //如果当前是未定位的状态   则获取的是末次位置
						   $("#longitude").attr("value",  result.data.longitude);
						   $("#latitude").attr("value", result.data.latitude);						   
						   }
				   } else {
					  alert(result.msg);
				   }
			 },            
		   });		
		}
		
		
		
		//初始化对讲播放插件
		function InitTalkSpeaker() {
				var AudioSpeakerFlashStr = '<object type="application/x-shockwave-flash" ' + 'name="voiceTalkOut" talkId="" termSn="" ' + 'data="./rtmp_player/StrobeMediaPlayback.swf" ' + 'width="100%" height="100%" id="voiceTalkOut"' + 'style="visibility:visible;">' + '<param name="allowFullScreen" value="false">' + '<param name="allowScriptAccess" value="always">' + '<param name="bgcolor" value="#ffffff">' + '<param name="menu" value="false">' + '<param name="flashvars" value="javascriptCallbackFunction=onAudioplayerCreated&controlBarMode=none&autoPlay=true&volume=9">' + '</object>';
				$("#voiceOut").empty().append(AudioSpeakerFlashStr);
		}
		
		//初始化对讲麦克风插件
		function InitTalkMic() {		
			var AudioMicFlashStr = '<object type="application/x-shockwave-flash" ' + 'name="voiceTalkIn" talkId="" termSn="" ' + 'data="./rtmp_player/dcwIvs_Mic.swf" ' + 'width="220" height="140" id="voiceTalkIn"' + 'style="visibility:visible;">' + '<param name="allowFullScreen" value="false">' + '<param name="allowScriptAccess" value="always">' + '<param name="bgcolor" value="#ffffff">' + '<param name="wmode" value="transparent">' + '<param name="flashvars" value="javascriptCallbackFunction=onAudioplayerCreated&controlBarMode=none&autoPlay=true&volume=9">' + '</object>';
		    $("#voiceIn").empty().append(AudioMicFlashStr);
		}
		
		
		//呼叫
		function startVoiceCall(){
			var jssesionId=$("#jssesionId").val();			
			var nmsName=$("#devicename").val();
			var channelId=33;//对讲通道编号  对讲固定为33
			var param='{'+'"nmsName":"'+nmsName+'",'+'"channelId":"'+channelId+'"'+'}';
		
			
			$.ajax({
            type: 'POST',
			url: 'http://'+serverip+':52467/openApi/voiceCalls.dcw',
			data:param,
			cache:false,			
			contentType:'application/json',
			headers: {
                'jssesionId': jssesionId  //jssesionId要放在header中
            },
			dataType: 'json',
            success: function(result){
                 if(result.code == 200){
					talkId=result.data.talkId;					
					 if(result.data.error.errorcode==0){
						var pos =(result.data.urlIn+"").lastIndexOf('/');
						var live =(result.data.urlIn+"").substring(0, pos);
						var name =(result.data.urlIn+"").substring(pos + 1);

						var rtmp_streamer = document.getElementById("voiceTalkIn");  
						rtmp_streamer.publish(live, name);


						//$('#closeVoiceCalls').attr('data-talking', 'yes');
						audioPlayer = document.getElementById("voiceTalkOut");
						audioPlayer.setMediaResourceURL(result.data.url);
						audioPlayer.setAutoPlay(true);
					 }else if(result.data.error.errorcode==7){ //正在对讲
						//stopVoiceCall();
						alert("设备占线，请稍候再试！");
					 }
				  			    
				   } else {
					  alert(result.msg);
				   }
			 },            
		   });
			
			
			
		
		
		}
		
		//挂断
		function stopVoiceCall(){
			var jssesionId=$("#jssesionId").val();			
			var nmsName=$("#devicename").val();
			var channelId=33;//对讲通道编号  对讲固定为33
			
			
			var param='{'+'"nmsName":"'+nmsName+'",'+'"channelId":"'+channelId+'",'+'"talkId":"'+talkId+'"'+'}';					
			
			$.ajax({
            type: 'POST',
			url: 'http://'+serverip+':52467/openApi/stopVoiceCalls.dcw',
			data:param,
			cache:false,			
			contentType:'application/json',
			headers: {
                'jssesionId': jssesionId  //jssesionId要放在header中
            },
			dataType: 'json',
            success: function(result){
                 if(result.code == 200){
					var rtmp_streamer = document.getElementById("voiceTalkIn");
					if(rtmp_streamer!=null){
						rtmp_streamer.disconnect();
					}
					 audioPlayer = document.getElementById("voiceTalkOut");
					if (audioPlayer != null) {
						audioPlayer.stop2();
						audioPlayer.setMediaResourceURL("");
						audioPlayer.setAutoPlay(false);
					}
					
				   } else {
					  alert(result.msg);
				   }
			 },            
		   });
		}

		</script>
        
       
        
        

		<div>
        服务器IP：<input name="serverip" id="serverip" type="text" value="120.79.137.194"  /><br>
       用户名: <input name="account" id="account" type="text" value="sjzc"  /><br>
       密码: <input name="password" id="password" type="text"  value="000000" /><br>
        
                <button id="login">登录</button></br>
                
                
                会话ID：<input name="jssesionId" id="jssesionId" type="text"  /><br> 
                
                设备编号：<input name="devicename" id="devicename" type="text"  value="860301100061044" /><br>
                <button id="getTermSn">获取设备ID</button></br>
                
                设备id：<input name="termsn" id="termsn" type="text"  /><br> 
                <button id="btn_getOnlieStatus">获取设备在线状态</button></br>
                
                在线状态:<input name="onlineStatus" id="onlineStatus" type="text"  /><br> 
				
                <button id="locStatus">获取GPS定位信息</button><br>                
                定位状态：：<input name="gpsStatus" id="gpsStatus" type="text"  /><br> 
                经度：<input name="longitude" id="longitude" type="text"  /><br> 
                维度：<input name="latitude" id="latitude" type="text"  /><br> 
                
                
                实时视频：<br>
				
                <div id="videoflash">                
                </div>           
				<button id="play">播放</button>                
                <button id="stop">停止</button><br>
				
				
				对讲：<br>
				
				<div id="voiceIn"></div>  <!--声音播放-->
				
				<div id="voiceOut"> <!--声音采集-->
				</div>
				
				<button id="btn_voiceCall">呼叫</button>                
                <button id="btn_voiceStop">挂断</button><br>
				
                
		</div>
	</body>
    <script type="text/javascript">
	$("#login").click(function(){
		login();
		
		});
		
		
	$("#getTermSn").click(function(){
		getTermSn();
	
	});
	
	
	
	//初始化实时视频播放flash
	var swf=new swfobject();
	swf.embedSWF("./rtmp_player/StrobeMediaPlayback.swf", "videoflash",400,400,1);
	//设置窗口数量
	swf.setWindowNum(1);
	//设置服务器地址
	swf.initServer($("#serverip").val(),"52467");
	
	//播放
	$("#play").click(function(){		
		
		var jssesionId=$("#jssesionId").val();  //会话ID
		var nmsName=$("#devicename").val();  //设备编号
		var streamType=1;  //0：主码流  1：次码流
		var channelId=1;  //视频通道编号  从1开始
		var index=0;  //视频播放窗口序号 从0开始
		swf.startVideo(index,jssesionId,nmsName,channelId,streamType);	
	});
	
	//停止
	$("#stop").click(function(){	
	
		swf.stopVideo(1);
	
	});
	//获取定位状态
	$("#locStatus").click(function(){	
	
		getLocStatus();
	
	});
    
	//获取设备在线状态
	$("#btn_getOnlieStatus").click(function(){
		
	
		getOnlineStatus();
	
	});
	
	
	//初始化对讲声音播放插件
	InitTalkSpeaker();
	//初始化对讲声音麦克风插件
	InitTalkMic();
	
	//语音呼叫
	$("#btn_voiceCall").click(function(){
	
		startVoiceCall();
		
	});
	
	//挂断
	$("#btn_voiceStop").click(function(){
	
		stopVoiceCall();
		
	});
		
		   
		   
	
	
	
	</script>



</html>
